﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Workflow.Common.Dao;
using Workflow.Dto;
using Workflow.IDAO;
using Workflow.Model;
using NHibernate.Linq;

namespace Workflow.DAO
{
	public class ApplicatDao : RepositoryBase<Applicat>, IApplicatDao
	{

		public Applicat GetApplicatByDto(ApplicatQueryDto applicatQueryDto)
		{
			var result = Session.Query<Applicat>();

			if (applicatQueryDto != null)
			{
				if (!string.IsNullOrEmpty(applicatQueryDto.Id))
				{
					result = result.Where(x => x.ID == applicatQueryDto.Id);
				}

				if (!string.IsNullOrEmpty(applicatQueryDto.ISID))
				{
					result = result.Where(x => x.ISID == applicatQueryDto.ISID);
				}
			}
			return result.ToList().FirstOrDefault();
			
		}

		public Applicat GetApplicatByMail(string mail)
		{
			var result = Session.Query<Applicat>();

			result = result.Where(x => x.Email == mail);
			
			return result.ToList().FirstOrDefault();

		}
	}
}
